
import Cookies from 'js-cookie';

export const Local = {
    set(key: string, value: any) {
        window.localStorage.setItem(key, JSON.stringify(value));
    },
    get(key: string): any {
        let json = <string>window.localStorage.getItem(key);
        return JSON.parse(json);
    },
    remove(key: string) {
        window.localStorage.removeItem(key);

    },
    clear() {
        window.localStorage.clear();
    }
}

export const Session = {
    set(key: string, value: any) {
        if (key==='token') return Cookies.set(key, value);
        window.sessionStorage.setItem(key, JSON.stringify(value));
    },
    get(key: string): any {
        if(key==='token') return Cookies.get(key);
        let json = <string>window.sessionStorage.getItem(key);
        return JSON.parse(json);
    },
    remove(key: string) {
        if(key==='token') Cookies.remove(key);
        window.sessionStorage.removeItem(key);

    },
    clear() {
        Cookies.remove("token");
        window.sessionStorage.clear();
    }
}